//
//  Store.swift
//  TestModelActor
//
//  Created by 罗万能 on 2025/6/18.
//

import Foundation
import SwiftData
import RoNetApiLibrary
class Store: ObservableObject{
    var modelContainer: ModelContainer
    @Published var actor :BeautyModelActor
    init(modelContainer: ModelContainer) {
        self.modelContainer = modelContainer
        self.actor = BeautyModelActor(modelContainer: modelContainer)
        
    }
    
    func appendNewBeauty(){
        Task{
            guard let address = await RoNetApiLibrary.shared.fetchBeautyGirlVideoToNetAddress() else{ return }
            await actor.append(from:  address)
        }
    }
    func appendNewBeautyAndDownload(){
        Task{
            guard let address = await RoNetApiLibrary.shared.fetchBeautyGirlVideoToNetAddress() else{ return }
//            await actor.append(from:  address)
            await actor.appendAndDownload(from: address)
        }
    }
    
    func remove(model: BeautyModel){
        Task{
            await actor.remove(model: model)
        }
    }
    func download(model: BeautyModel){
        Task{
            let manager = BeautyDownloadManager(actor: actor, model: model)
            await manager.startDownload()
        }
    }
}
